<?php
require_once '../lib/Validate.php';
require_once 'model.php';


/**
 * user_model Class
 * Model for the user table
 * 
 * @author Victor Nava
 *
 */
class user_model extends model {
	function __construct(){
		parent::__construct('users');
	}
	
	/**
	 * (non-PHPdoc)
	 * @see app/model#get($id)
	 */
	function get($id){
		$user = parent::get($id);
		unset($user['password']);
		return $user;
	}

	/**
	 * Gets a user by its email and password
	 * 
	 * @param $email
	 * @param $password
	 * @return Associative Array representing a user
	 */
	function getByEmailPass($email, $password){
		//TODO sanitize
		$sql = "SELECT * FROM `users` WHERE `email`='$email' and `password`='$password'";
		
		try{
			return $this->dbCon->query($sql)->fetch(PDO::FETCH_ASSOC);
		}catch (PDOException $e){
			//TODO find proper way to display message?
			echo $e;
			return null;
		}
	}
}
?>